﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LeMigue.Framework.Utils
{
    public class TreeNode<T>
    {
        private TreeNode<T> _parent;
        private T _value;
        private List<TreeNode<T>> _children;

        public IEnumerable<TreeNode<T>> Children
        {
            get { return _children; }
        }

        public TreeNode<T> Parent
        {
            get { return _parent; }
        }

        public bool IsRoot
        {
            get { return _parent == null; }
        }
        public T Value
        {
            get { return _value; }
        }
        public TreeNode(T value)
        {
            _value = value;
            _children = new List<TreeNode<T>>();
        }

        public void Add(TreeNode<T> child)
        {
            _children.Add(child);
            child.SetParent(this);
        }

        public void Remove(TreeNode<T> child)
        {
            child.SetParent(null);
            _children.Remove(child);
        }

        private void SetParent(TreeNode<T> parent)
        {
            _parent = parent;
        }
    }
}
